Skip to content

fix: close the socket opened to log out of a removed workspace - #7918

Merged
diegolmello merged 2 commits into
developfrom
fix/close-removed-workspace-socket
Nov 24, 2026
Merged

diegolmello merged 2 commits into
developfrom
fix/close-removed-workspace-socket

Conversation

@diegolmello

@diegolmello diegolmello commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Proposed changes

Removing a workspace from the workspace switcher logs out of it with a short-lived SDK client. That client opens a DDP WebSocket for the login, but nothing ever closed it. The socket stayed open for the rest of the app's life, and after any network drop it reconnected to the removed workspace every few seconds.

logoutFromServer now creates the client before the try and always calls disconnect() in a finally, on success and when login, push.token or logout fails. The SDK's disconnect() cancels any scheduled reopen, so the socket stays closed.

Issue(s)

https://rocketchat.atlassian.net/browse/NATIVE-1848

How to test or reproduce

  1. Log in to two workspaces.
  2. Open the workspace switcher (tap the rooms list header) and long-swipe the other workspace to delete it.
  3. Wait a minute, toggle airplane mode on and off.
  4. Inspect the app's TCP connections (/proc/net/tcp on a rooted emulator, filtered by the app's uid).
  5. Before: a new connection to the removed workspace opens once the network returns. After: none.

Run on an Android emulator (Pixel, API 34, debug build). Removed workspace: mobile.qa.rocket.chat (resolves to 52.23.78.116); kept workspace: open.rocket.chat. Each row is a count of the app's ESTABLISHED sockets to that address.

Before the fix:

== 60s after removal
   2 104.20.22.143:443 open.rocket.chat
   2 52.23.78.116:443 mobile.qa.rocket.chat
== airplane mode on
   (no remote sockets)
== 40s after airplane mode off
   2 172.66.161.172:443 open.rocket.chat
   1 52.23.78.116:443 mobile.qa.rocket.chat   <- reconnected to the removed workspace

With the fix:

== 60s after removal
   2 104.20.22.143:443 open.rocket.chat
   1 172.66.161.172:443 open.rocket.chat
   1 52.23.78.116:443 mobile.qa.rocket.chat   <- idle connection from before the removal
== airplane mode on
   (no remote sockets)
== 40s after airplane mode off
   2 104.20.22.143:443 open.rocket.chat       <- nothing to the removed workspace

Local Metro and other non-workspace sockets are left out of both listings.

Screenshots

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

Nothing changes on screen, so there is no video; the socket listings above are the evidence. The two new tests in logout.test.ts fail without the change: one covers the success path, one a failing login.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup when removing a server: its connection is disconnected even if signing in with a saved session token fails.
    • The connection is also disconnected after logout or if another cleanup step encounters an error, helping prevent connections from being left open.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

logoutFromServer now disconnects its workspace client in a finally block and logs disconnect failures. Tests cover resume-token login and verify that disconnection still occurs when login rejects.

Changes

Workspace logout

Layer / File(s) Summary
Workspace logout and cleanup
app/lib/methods/logout.ts, app/lib/methods/__tests__/logout.test.ts
logoutFromServer disconnects its workspace client in finally and logs disconnect failures. Tests verify that removed-workspace logout uses the stored resume token and disconnects after success or login failure.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested labels: type: bug

Suggested reviewers: otaviostasiak, rohit3523

Merge Risk: Minimal · up to 887f9

Removing a workspace now closes the short-lived connection used to log out of it, so the removed workspace should no longer reconnect after a network drop. Tests cover disconnect after a successful logout and after a failed login. No remaining merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: logoutFromServer now closes the short-lived SDK socket opened to log out of a removed workspace. The raw summary confirms the disconnect in a finally block and the rel…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: logoutFromServer now closes the short-lived SDK socket opened to log out of a removed workspace. The raw summary confirms the disconnect in a finally block and the related test coverage. The title is specific and matches the changeset.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Errors were encountered while retrieving linked issues.

Errors: 1

  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2820c7da-ce34-4bda-83ef-3fa4015c8447
Commits

Reviewing files that changed from the base of the PR and between f79425c and 887f95c.

Files selected for processing: 1

  • app/lib/methods/__tests__/logout.test.ts
Files with no reviewable changes: 1

  • app/lib/methods/tests/logout.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@OtavioStasiak OtavioStasiak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@diegolmello
diegolmello merged commit 6c9e230 into develop Nov 24, 2026
24 of 26 checks passed
@diegolmello
diegolmello deleted the fix/close-removed-workspace-socket branch November 24, 2026 17:00

This branch is waiting to be deployed

1 inactive and 2 waiting deployments
android_build — 887f95c2 Waiting Nov 23, 2026 by diegolmello via Build Android / Hold #7918
ios_build — 887f95c2 Waiting Nov 23, 2026 by diegolmello via Build iOS / Hold #7918
approve_e2e_testing — 887f95c2 Deployed Nov 23, 2026 by diegolmello via E2E Hold #7918
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants